package main

import (
	"io/ioutil"
	"time"

	"gopkg.in/yaml.v2"
)

type Config struct {
	Bind      string                       `yaml:"bind"`
	ApiList   map[string]map[string]string `yaml:apilist`
	PostParam map[string]map[string]string `yaml:postparam`
	TimeOut   time.Duration                `yaml:"timeout"`
}

func (cfg *Config) ParseConfigData(data []byte) error {
	if err := yaml.Unmarshal([]byte(data), &cfg); err != nil {
		return err
	}
	return nil
}

func (cfg *Config) ParseConfigFile(fileName string) error {
	data, err := ioutil.ReadFile(fileName)
	if err != nil {
		return err
	}
	return cfg.ParseConfigData(data)
}
